#include "map.h"

Map::Map()
{
	loadMap(mapPath);
}

Map::Map(std::string path)
{
    loadMap(path);
    this->mapPath = path;
}

Map::~Map()
{

}

void Map::loadMap(std::string path)
{
    std::string line;
	std::ifstream file(path);
    if (file.is_open()) {
        std::getline(file, line); this->mMap["level"] = std::stoi(line);
        std::getline(file, line); this->mMap["gridSize"] = std::stod(line);
        std::getline(file, line); this->mMap["startX"] = std::stod(line);
        std::getline(file, line); this->mMap["startY"] = std::stod(line);
        std::getline(file, line); this->mMap["rowNums"] = std::stoi(line);
        std::getline(file, line); this->mMap["colNums"] = std::stoi(line);
        std::getline(file, line); this->mMap["barrierNums"] = std::stoi(line);

        for (int i = 0; i <= int(mMap["barrierNums"]); i++) {
            std::getline(file, line);
            std::istringstream iss(line);
            int x, y;
            iss >> x >> y;
            this->barriers.push_back(point(x, y));
        }
        file.close();
    }
    else {
        std::cerr << "Unable to open file: " << path << std::endl;
    }
}

std::map<std::string, double> Map::getMap()
{
    return this->mMap;
}

std::vector<point> Map::getBarriers()
{
    return this->barriers;
}